<template>
	<view>
		<uni-popup ref="upsetup" mode="center">
			<view class="bgfff  ra20 width880 pb50 text-left">
				<image @click="$refs.upsetup.close()" mode="widthFix"
					class="image posiab zindex15 right30 top20 width50" src="/static/img/bi.png"></image>
				<view class="size36 color333 bold  zindex5 flex-a-i ml50 pt30">
					<view class="wh6-30 mt8 bg2C7BFF mr15"></view>云会议室设置
				</view>
				<view class="pg50 ">
					<view class="flex-a-i">
						<view class="width250 text-right"><text class="colorFC474C">*</text>云会议室名称：</view>
						<el-input class="flex1" maxlength="30" v-model="room_name" placeholder="输入云会议室名称"></el-input>
					</view>
					<view class="flex-a-i mt50 mb50">
						<view class="width250 text-right">参会密码：</view>
						<el-input class="flex1" show-password  maxlength="10" v-model="join_pwd" placeholder="请输入4-10位数字"></el-input>
					</view>
					<view class="flex-a-i">
						<view class="width250 text-right"><text class="colorFC474C">*</text>主持密码：</view>
						<el-input class="flex1" show-password maxlength="10" v-model="ctrl_pwd" placeholder="请输入4-10位数字"></el-input>
					</view>
					<view class="flex-ju-c mt80">
						<view @click="$refs.upsetup.close()" class="wh152-64 borderd0d6dc flex-ju-c ra5">取消</view>
						<view @click="setName" class="wh152-64 bg165DFF colorfff flex-ju-c ml60 ra5">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		name:"meeting-setup",
		data() {
			return {
				room_name:"",
				join_pwd:"",
				ctrl_pwd:"",
			};
		},
		
		methods:{
			
			get_room_info() {
				uni.showLoading()
				return new Promise((resolve, reject) => {
					loginMgr.get_self_room_info().then(res => {
						resolve(res)
					})
				})
			},
			open(){
				this.get_room_info().then(res => {
					uni.hideLoading()
					this.ctrl_pwd = res.ctrl_pwd
					this.join_pwd = res.join_pwd
					this.room_name = res.room_name
					this.$refs.upsetup.open()
				})
			},
			setName(){
				if (!this.room_name) {
					uni.showToast({
						title:"会议室名称空",
						icon:"none"
					})
					
					return
				}
				if (!this.ctrl_pwd) {
					uni.showToast({
						title:"主持密码空",
						icon:"none"
					})
					
					return
				}
				if(this.join_pwd&&this.join_pwd.length<4){
					uni.showToast({
						title:"参会密码最少4位数",
						icon:"none"
					})
					return
				}
				if(this.ctrl_pwd.length<4){
					uni.showToast({
						title:"主持密码最少4位数",
						icon:"none"
					})
					return
				}
				
				
				if (this.ctrl_pwd == this.join_pwd) {
					uni.showToast({
						title:"参会密码与主持密码不能相同",
						icon:"none"
					})
					
					return
				}
				if (!this.isNumeric(this.ctrl_pwd)) {
					uni.showToast({
						title:"密码只能为数字",
						icon:"none"
					})
					
					return
				}
				if (this.join_pwd && !this.isNumeric(this.join_pwd)) {
					uni.showToast({
						title:"密码只能为数字",
						icon:"none"
					})
					
					return
				}
				this.$emit('setName',this.room_name,this.join_pwd,this.ctrl_pwd)
			},
			isNumeric(str) {
				return /^\d+$/.test(str);
			},
			close(){
				this.$refs.upsetup.close()
			}
			
		}
	}
</script>

<style>

</style>